/*
 * CBombManager.h
 *
 *      Author: grifos
 */

#ifndef CBOMBMANAGER_H_
#define CBOMBMANAGER_H_
#include "CMapNode.h"
#include "CJoueur.h"
#include "CObject3d.h"

#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Quat>
#include <osg/Matrix>
#include <osg/ShapeDrawable>
#include <osg/Geometry>
#include <osg/Geode>
#include <osg/Transform>
#include <osg/Material>
#include <osg/NodeCallback>
#include <osg/Depth>
#include <osg/CullFace>
#include <osg/TexMat>
#include <osg/TexGen>
#include <osg/TexEnv>
#include <osg/TexEnvCombine>
#include <osg/TextureCubeMap>
#include <osg/VertexProgram>
#include <osg/LineSegment>
#include <osg/MatrixTransform>
#include <osg/StateSet>
#include <osg/Texture2D>
#include <osg/Billboard>
#include <osg/BlendFunc>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osg/AlphaFunc>


class CBombManager {
private:
	CMapNode * _map;
	CJoueur  * _joueur;
	CObject3d * _bomb;
	osg::ref_ptr<osg::Geode> _blowGeode;
	osg::ref_ptr<osg::StateSet> _bombAttribute;
	osg::MatrixTransform * _blowPos;
	osg::Group * _root;
	osg::Vec3 _safePoint;
	osg::ref_ptr<osg::MatrixTransform> _bombBeacon;
	bool _grabed;
	float _bombPos[5][3];
	int _nbBomb;
	float _blowRadius;
	bool _bombBlowed;
	float _timeSinceBlow;

public:
	CBombManager(CMapNode* m, CJoueur * j, osg::Group * root, int glLighting);
	virtual ~CBombManager();

	void addBomb();
	void blowBomb();
	void update(float delta, osg::Vec3 movement, osg::Vec3 wandPos, osg::Vec3 headPos);
	void grabBomb(osg::Vec3 wandPos);
	bool checkIntersect(osg::Vec3 wandPos, osg::Vec3 headPos);
	osg::Vec3 getBombPosInMap(){ return _bomb->getPosition(); }
	osg::Vec3 getBombPosInWorld(osg::Vec3 wandPos, osg::Vec3 headPos);
	osg::Vec3 getWandPosInWorld(osg::Vec3 wandPos, osg::Vec3 headPos);
	bool checkDiffusable(osg::Vec3 wandPos, osg::Vec3 headPos);
	osg::Drawable* createBeaconDrawable(const float & scale, osg::StateSet* bbState);
};

#endif /* CBOMBMANAGER_H_ */
